package com.mingqi.enetconnected.primary.mytask.adapter;


import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingqi.enetconnected.R;
import com.mingqi.enetconnected.util.CenterAlignImageSpan;
import com.mingqi.enetconnected.util.resource.ResourceUtils;

import java.util.List;

/**
 * Created by li on 2018/8/9.
 * WeChat 18571658038
 * author LiWei
 */

public class MyTaskAdapter extends BaseQuickAdapter<String,BaseViewHolder> {

    public MyTaskAdapter(@Nullable List<String> data) {

        super(R.layout.item_my_task,data);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {

        helper.addOnClickListener(R.id.iv_call_phone);
        helper.addOnClickListener(R.id.iv_send_message);
        helper.addOnClickListener(R.id.rl_came_here);
        helper.addOnClickListener(R.id.rl_go_sign);

        TextView tvAddressTitle = helper.getView(R.id.tv_address_title);

        String addressStr = "苏州市工业园区迎松小区15幢201苏州市工业园区迎松小区15幢201  ";
        SpannableString sp = new SpannableString(addressStr);

        //获取一张图片
        Drawable drawableVip = ResourceUtils.getDrawable(R.drawable.ic_vip);
        drawableVip.setBounds(0, 0, drawableVip.getMinimumWidth(), drawableVip.getMinimumHeight());

        //居中对齐imageSpan

        CenterAlignImageSpan imageSpan = new CenterAlignImageSpan(drawableVip);
        sp.setSpan(imageSpan, addressStr.length() - 1, addressStr.length(), ImageSpan.ALIGN_BASELINE);

        tvAddressTitle.setText(sp);
        int position = helper.getLayoutPosition();
        if(position % 2 == 1) {

            helper.setGone(R.id.ll_go_sign,false);
        } else {

            helper.setGone(R.id.ll_go_sign,true);
        }
    }
}
